<template>
<div style="margin: auto;line-height: 100px">
  <div style="display: flex;justify-content: center">
    <h1>修改密码</h1>
  </div>

  请输入旧密码:<el-input v-model="userObj.pwd" placeholder="请输入旧密码" style="width: 300px"/><br>

  请输入新密码:<el-input v-model="userObj.newPwd" placeholder="请输入新密码" style="width: 300px"/><br>

  请确认新密码:<el-input v-model="userObj.surePwd" placeholder="请确认新密码" style="width: 300px"/><br>

  <el-button type="primary" @click="changePwd()">修改</el-button>

<!--  <el-form-->
<!--      ref="userForm"-->
<!--      :model="userObj"-->
<!--      :rules="rules"-->
<!--      label-width="120px"-->
<!--      class="demo-ruleForm"-->
<!--      status-icon-->
<!--      style="width: 400px;"-->
<!--  >-->
<!--    <el-form-item label="请输入旧密码" prop="pwd">-->
<!--      <el-input v-model="userObj.oldPwd" />-->
<!--    </el-form-item>-->
<!--    <el-form-item label="请输入新密码" >-->
<!--      <el-input v-model="userObj.newPwd" />-->
<!--    </el-form-item>-->
<!--    <el-form-item label="请确认新密码" >-->
<!--      <el-input v-model="userObj.surePwd" />-->
<!--    </el-form-item>-->

<!--    <el-form-item>-->
<!--      <el-button type="primary" @click="changePwd()">添加</el-button>-->
<!--    </el-form-item>-->
<!--  </el-form>-->
</div>

</template>

<script>
import axios from "axios"
export default {
name: "changePwd",
data(){
    return{
      loginUser:'',
      userObj:{
        newPwd:'',
        surePwd:''
      },

        }
    },
  methods:{
  getLoginUser(){
      axios.get("/project/user/getLoginUser").then(resp=>{
        this.loginUser=resp.data;
      });
    },
  changePwd(){
    if (this.userObj.pwd==this.loginUser.pwd&&this.userObj.newPwd==this.userObj.surePwd){

      axios.get("/project/user/updatePwd",{params:{
        pwd:this.userObj.newPwd
        }
        }).then(resp=>{
          if (resp.data=="ok"){
            alert("ok")
            this.$router.push("/login")
          }
      })
    }
    }

  },
  created() {
  this.getLoginUser();
  }
}
</script>

<style scoped>

</style>